﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using sBlog.Net.Domain.Entities;
using sBlog.Net.Domain.Interfaces;

namespace sBlog.Net.Controllers
{
    public class TestSpeedController : Controller
    {
        private readonly ITag _tagRepository;

        public TestSpeedController(ITag tagRepository)
        {
            _tagRepository = tagRepository;
        }

        public ActionResult Index()
        {
            ViewBag.lstStore = stopWatchStoreProcedure();
            ViewBag.lstNoStore = stopWatchLinq();
            return View();
        }

        public string stopWatchStoreProcedure()
        {
            System.Diagnostics.Stopwatch myStopWatch = new System.Diagnostics.Stopwatch();
            //Start StopWatch...
            myStopWatch.Start();
            for (int i = 0; i < 10000; i++)
            {
                IEnumerable<TagEntity> tagLst = _tagRepository.getTag();
            }
            //Stop StopWatch...
            myStopWatch.Stop();
            string lTime = "Time Taken : " + myStopWatch.Elapsed.Hours.ToString() + " : " + myStopWatch.Elapsed.Minutes.ToString() + " : " + myStopWatch.Elapsed.Seconds.ToString() + " : " + myStopWatch.Elapsed.Milliseconds.ToString();
            return lTime;
        }

        public string stopWatchLinq()
        {
            System.Diagnostics.Stopwatch myStopWatch = new System.Diagnostics.Stopwatch();
            //Start StopWatch...
            myStopWatch.Start();
            for (int i = 0; i < 10000; i++)
            {
                IEnumerable<TagEntity> tagLst = _tagRepository.GetAllTags().Take(50);
            }
            //Stop StopWatch...
            myStopWatch.Stop();
            string lTime = "Time Taken : " + myStopWatch.Elapsed.Hours.ToString() + " : " + myStopWatch.Elapsed.Minutes.ToString() + " : " + myStopWatch.Elapsed.Seconds.ToString() + " : " + myStopWatch.Elapsed.Milliseconds.ToString();
            return lTime;
        }
    }
}
